/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.Image;

public class Bullet {

    private int _damage;
    private int _weight;
    private Sprite _sprite;
    private ThrowingObject throwingObject;

    public Bullet(String fileName, int w, int h, int nFrame) {
        try {
            _sprite = new Sprite(Image.createImage(fileName), w, h);
            throwingObject = new ThrowingObject();
            _sprite.defineReferencePixel(w / 2, h / 2);
            _sprite.defineCollisionRectangle(0, 0, w, h);
        } catch (Exception ex) {
        }

    }

    public void setThrowParameter(int x0, int y0, double throwAngle, double thrownPower) {
        _sprite.setPosition(x0, y0);
        throwingObject.setThrowParameter(throwAngle, thrownPower);
    }

    public void activate() {
        throwingObject.activate();
        _sprite.setVisible(true);
    }
    public boolean isActivate()
    {
        return _sprite.isVisible();
    }

    public void deactivate() {
        throwingObject.deactivate();
        _sprite.setVisible(false);
    }

    public void run() {
        throwingObject.run(_sprite);
        _sprite.nextFrame();
    }

    public Sprite getSprite() {
        return _sprite;
    }
    
    public boolean hit(Sprite sprite)
    {
        if(_sprite.collidesWith(sprite, true))
            return true;
        return false;
    }
    
}
